package com.inforich.web.controller.orderManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.orderManage.domain.Transport;
import com.inforich.orderManage.service.ITransportService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 运输Controller
 *
 * @author hjm
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/orderManage/transport")
public class TransportController extends BaseController {

  @Autowired
  private ITransportService transportService;

  /**
   * 查询运输列表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:transport:list')")
  @GetMapping("/list")
  public Page<Transport> list(Page<Transport> page, Transport transport) {
    Map<String, Object> map = beanToMap(transport);
    transportService.pageTransport(page, map);
    return page;
  }


  /**
   * 导出运输列表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:transport:export')")
  @Log(title = "运输", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, Transport transport) {
    Map<String, Object> map = beanToMap(transport);
    List<Transport> list = transportService.listTransport(map);
    ExcelUtil<Transport> util = new ExcelUtil<Transport>(Transport.class);
    util.exportExcel(response, list, "运输数据");
  }

  /**
   * 获取运输详细信息
   */
  @PreAuthorize("@ss.hasPermi('orderManage:transport:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") String id) {
    return AjaxResult.success(transportService.getTransportById(id));
  }

  /**
   * 新增运输
   */
  @PreAuthorize("@ss.hasPermi('orderManage:transport:add')")
  @Log(title = "运输", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody Transport transport) {
    return toAjax(transportService.insertTransport(transport));
  }

  /**
   * 修改运输
   */
  @PreAuthorize("@ss.hasPermi('orderManage:transport:edit')")
  @Log(title = "运输", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody Transport transport) {
    return toAjax(transportService.updateTransport(transport));
  }

  /**
   * 删除运输
   */
  @PreAuthorize("@ss.hasPermi('orderManage:transport:remove')")
  @Log(title = "运输", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable String[] ids) {
    return toAjax(transportService.removeByIds(Arrays.asList(ids)));
  }
}
